<?php
require_once dirname(__FILE__) . '/metadata.php';
require_once dirname(__FILE__) . '/DbUtils.class.php';
require_once dirname(__FILE__) . '/includes/MiscUtils.class.php';

settle_bank();

function settle_bank() {
  $myPdo = DbUtils::createPdoInst();
  $tmps = DbUtils::get($myPdo, TABLE_NAME_PREFIX_MODULE . 'data_transaction', NULL, NULL, NULL, NULL, NULL, NULL)->d;
  if (count($tmps) > 0) {
    foreach ($tmps as $tmp) {
      $cond_vals = new stdClass();
      $cond_vals->c = 't.transaction_track_id = :v1';
      $cond_vals->v = array(':v1' => $tmp->track_id);
      $settles = DbUtils::get($myPdo, TABLE_NAME_PREFIX_MODULE . 'data_transaction_settle', $cond_vals, NULL, NULL, NULL, NULL, NULL)->d;
      if (count($settles) > 0) {
      	foreach ($settles as $obj) {
	        $obj->bank_id = isset($tmp->bank_id) ? $tmp->bank_id : 0;
          $obj->account_no = isset($tmp->account_no) ? $tmp->account_no : '';
          $obj->account_name = isset($tmp->account_name) ? $tmp->account_name : '';
          $obj->bank = isset($tmp->bank) ? $tmp->bank : '';
          $obj->branch = isset($tmp->branch) ? $tmp->branch : '';
          $obj->city = isset($tmp->city) ? $tmp->city : '';
          $obj->country = isset($tmp->country) ? $tmp->country : '';
          $obj->swift_code = isset($tmp->swift_code) ? $tmp->swift_code : '';
	        DbUtils::update($myPdo, TABLE_NAME_PREFIX_MODULE . 'data_transaction_settle', $obj);
      	}
      }
    }
    echo 'Successfully';
  }
}
?>